import kotlinx.coroutines.*
import plugins.SystemCfgPlugin
import java.io.File

fun main(args: Array<String>) = runBlocking {
    initPj()
    println("jnotify 服务启动")
    launch { doSync() }
    launch { loadPlugin() }
    println("Done")
}

suspend fun loadPlugin() = coroutineScope {
    val plugns = arrayOf(SystemCfgPlugin())
    plugns.forEach { it.install();it.exec() }
    plugns.forEach {
        launch {
            while (true) {
                it.exec()
                delay(1000 * 60 * 60 * 2)
            }
        }
    }
}

/**
 * 解析同步项目所有的仓库到远程
 * 本地文件不断推送到远程
 * */
suspend fun doSync() {
    while (true) {
        println("开始同步仓库")
        syncLocalRemoteAll()
        doSyncRepo()
        delay(60 * 1000)
    }
}
// Concurrently executes both sections
suspend fun doNotify() = coroutineScope { // this: CoroutineScope
    launch {
        delay(2000L)
        println("World 2")
    }
}